﻿using System;
using System.Windows;
using System.Windows.Controls;
using client.viewmodels;
using client.helpers;

namespace client
{
    public partial class MainWindow : Window
    {
        private MainViewModel _vm = null;


        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.Title = $"{LocStringHelper.GetInstance().GetString("Title")}";
            _vm = new MainViewModel();
            this.DataContext = _vm;
            MainWindowReference.MainWindow = this;

            _loginView.DataContext = _vm;
            _testCaseView.DataContext = _vm;
            _testPlanView.DataContext = _vm;
            _vm.CurrentVisiblePage = Constant.LoginPageName;
        }

        private void SwitchPageRadioButton_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton rb = sender as RadioButton;
            if (rb != null)
            {
                switch (rb.Tag.ToString())
                {
                    case Constant.TestCasePageName:
                        _vm.CurrentVisiblePage = Constant.TestCasePageName;
                        break;
                    case Constant.TestPlanPageName:
                        _vm.CurrentVisiblePage = Constant.TestPlanPageName;
                        break;
                    default:
                        break;
                }
            }
        }

        /*
         // richtextbox demo
                private void Button_Click(object sender, RoutedEventArgs e)
                {
                    OpenFileDialog dlg = new OpenFileDialog();
                    var filters = new List<string>
                    {
                        "*.jpg;*.jpeg|*.jpg;*.jpeg",
                        "*.png|*.png",
                        "*.bmp|*.bmp",
                        "*.*|*.*"
                    };
                    dlg.Filter = string.Join("|", filters);
                    dlg.FilterIndex = filters.Count;
                    dlg.Title = "选择图片文件";
                    dlg.CheckFileExists = true;
                    dlg.CheckPathExists = true;
                    if (dlg.ShowDialog() == true)
                    {
                        myRichTextBox.InsertImage(dlg.FileName);
                    }
                }

                private void TestButton_Click(object sender, RoutedEventArgs e)
                {
                    var buffer = myRichTextBox.ExportData();
                    myRichTextBox2.ImportData(buffer);
                }*/
    }
}
